package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.frontierCommand.vo.TPatrolRecordVo;
import com.ruoyi.system.mobile.bo.TPatrolRecordAddBo;
import com.ruoyi.system.mobile.bo.TPatrolRecordEditBo;
import com.ruoyi.system.mobile.bo.TPatrolRecordQueryBo;
import com.ruoyi.system.mobile.service.PatrolRecordService;
import com.ruoyi.system.mobile.vo.PatrolRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 巡护记录Controller
 * 
 * @author ruoyi
 * @date 2021-05-20
 */
@Api(value = "巡护记录控制器", tags = {"巡护记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mobile/patrolRecord")
public class PatrolRecordController extends BaseController {

    private final PatrolRecordService iTPatrolRecordService;

    /**
     * 查询巡护记录列表
     */
    @ApiOperation("查询巡护记录列表")
    @GetMapping("/list")
    public TableDataInfo<PatrolRecordVo> list(TPatrolRecordQueryBo bo) {
        startPage();
        List<PatrolRecordVo> list = iTPatrolRecordService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 获取巡护记录详细信息
     */
    @ApiOperation("获取巡护记录详细信息")
    @GetMapping("/{id}")
    public AjaxResult<PatrolRecordVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTPatrolRecordService.queryById(id));
    }

    /**
     * 新增巡护记录
     */
    @ApiOperation("新增巡护记录")
    @Log(title = "巡护记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult<Void> add(@RequestBody TPatrolRecordAddBo bo) {
        return toAjax(iTPatrolRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改巡护记录
     */
    @ApiOperation("修改巡护记录")
    @Log(title = "巡护记录", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult<Void> edit(@RequestBody TPatrolRecordEditBo bo) {
        return toAjax(iTPatrolRecordService.updateByEditBo(bo) ? 1 : 0);
    }


}
